<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/unstandard-1.0" prefix="un"%>


<script type="text/javascript" src="<%=request.getContextPath()%>/js/dtree_checkbox.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/dtree.css" />

<un:bind var="LEAVE_NODE" type="com.bupt.liutong.admin.core.form.TreeNodeForm"
	field="LEAVE_NODE" />
<div id="dtree_checkbox">
	<script type="text/javascript">
		d = new dTree('d');
		<c:forEach var="treeNodeForm" items="${treeNodeFormList}">
			<c:if test="${treeNodeForm.nodeType != LEAVE_NODE}">
				<c:if test="${roleModuleAndOperMap[treeNodeForm.id]}">
					d.add(${treeNodeForm.id},${treeNodeForm.parentId},'<input type="checkbox" name="moduleId" id="checkbox${treeNodeForm.parentId},${treeNodeForm.id}" value="${treeNodeForm.id}" checked="checked" onclick="selectSonNode(this.id, this.checked);" />${treeNodeForm.name}','','','${treeForm.target}');
				</c:if>
				<c:if test="${roleModuleAndOperMap[treeNodeForm.id]==null}">
					d.add(${treeNodeForm.id},${treeNodeForm.parentId},'<input type="checkbox" name="moduleId" id="checkbox${treeNodeForm.parentId},${treeNodeForm.id}" value="${treeNodeForm.id}" onclick="selectSonNode(this.id, this.checked);" />${treeNodeForm.name}','','','${treeForm.target}');
				</c:if>
			</c:if>
			<c:if test="${treeNodeForm.nodeType == LEAVE_NODE}">
				<c:if test="${roleModuleAndOperMap[treeNodeForm.id]}">
					d.add(${treeNodeForm.id},${treeNodeForm.parentId},'<input type="checkbox" name="operId" id="checkbox${treeNodeForm.parentId},${treeNodeForm.id}" value="${treeNodeForm.id}" checked="checked" onclick="selectSonNode(this.id, this.checked);" />${treeNodeForm.name}','','','${treeForm.target}');
				</c:if>
				<c:if test="${roleModuleAndOperMap[treeNodeForm.id]==null}">
					d.add(${treeNodeForm.id},${treeNodeForm.parentId},'<input type="checkbox" name="operId" id="checkbox${treeNodeForm.parentId},${treeNodeForm.id}" value="${treeNodeForm.id}" onclick="selectSonNode(this.id, this.checked);" />${treeNodeForm.name}','','','${treeForm.target}');
				</c:if>
			</c:if>
		</c:forEach>
		document.write(d);
		d.openAll();
		
		function selectSonNode(checkboxId, checked){
			var ids = checkboxId.substr(8,checkboxId.length).split(",");
			var parentId = ids[0];
			var id = ids[1];
				var inputs = document.getElementById("dtree_checkbox").getElementsByTagName("input");
				for(var i=0; i<inputs.length; i+=1){
					if(inputs[i].type == "checkbox"){
						var inputIds = inputs[i].id.substr(8,checkboxId.length).split(",");
						if(inputIds[0] == id){
							inputs[i].checked = checked;
							selectSonNode(inputs[i].id, checked);
						}
					}
				}
		}
	</script>
</div>
